package com.qf.service;

import com.qf.dfa.SensitiveWordFilter;
import com.qf.model.StandardSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 敏感词 过滤
 * @author lixu
 */
@Service("dirtyWords")
@Slf4j
public class DirtyWordFilterServiceImpl implements FilterChainService {
    /**
     * 过滤  敏感词过滤
     *  发送短信的内容：       昨天  陈老师  来了   ，今天  走  了      识别出来里面有陈老师  敏感词 是需要过滤
     *
     *   1、先分词
     *   2、再遍历查找
     * @param standardSubmit
     * @return
     */
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        //1:短信内容
        String messageContent = standardSubmit.getMessageContent();
        //2:分词
        SensitiveWordFilter sensitiveWordFilter = SensitiveWordFilter.getInstance();
        int count = sensitiveWordFilter.checkSensitiveWord(messageContent, 0,
                SensitiveWordFilter.maxMatchType);
        if(count > 0){
            //有敏感词
            return false;
        }
        return true;
    }
}
